<!DOCTYPE html>
<html>
	<head>
		<title>设置个人资料</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/myInfo.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/plugins/form/jquery.form.js"></script>
		<script src="/js/checkLogin.js"></script>
		<script src="/js/common.js"></script>

		<script>
			$(function(){
				// 使用jrender 插件渲染数据 到页面
				$(".info").renderValues(user);
				$("#saveBtn").click(function(){
					$("#infoForm").ajaxSubmit({
						url:baseUrl + "/users/" + user.id,
						type:"put",
						success:function(data){
							if (data.success) {
								//把sessionStorage对象中的数据更新
								sessionStorage.setItem("user",JSON.stringify(data.data));
                                location.href="/mine/profiles.html";
                            } else {
								//保存失败
								$(document).dialog({
									content: data.msg,
									style: 'ios'
								});
							}
						}
					});
				});
				//渲染背景
				$(".myBg").css("background-image","url("+user.coverImgUrl+")");
				//1代表头像上传，2代表封面上传
				var tag;
				//设置头像点击事件
				$("#headImgBtn").click(function(){
					tag=1;
					$("[name=file]").click();
				});
				//设置背景点击事件
				$("#coverBtn").click(function(){
					tag=2;
					$("[name=file]").click();
				});
				//设置文件上传
				$("[name=file]").change(function(){
					if ($(this).val()) {
						$("#fileForm").ajaxSubmit({
							url:baseUrl + "/images",
							success:function(data){
								if (data.status == 1) {
                                    //图片上传成功
									if (tag == 1) {
										$("#headImg").attr("src",data.url);//设置头像图片
										$("[name=headImgUrl]").val(data.url);//把头像图片存入sessionStorage
                                    }else {
										$(".myBg").css("background-image","url("+data.url+")");//设置背景图片
										$("[name=coverImgUrl]").val(data.url);//把背景图片存入sessionStorage
									}
                                } else{
									//图片上传失败
									$(document).dialog({
										content: data.msg,
										style: 'ios'
									});
								}
							}
						});
					}
				});
			})
		</script>
			
	</head>

	<body style="background: url('/upload/2.bmp')">
		<form id="fileForm" enctype="multipart/form-data" method="post">
			<input type="file" name="file" hidden>
		</form>
		<div class="search-head">
			<div class="row nav-search">
				<div class="col">
					<a href="javascript:window.history.go(-1);">
						<span>取消</span>
					</a>
				</div>
				<div class="col">
					<span>设置个人资料</span>
				</div>
				<div class="col" >
					<a href="#" id="saveBtn" >
						<span>保存</span>
					</a>
				</div>
			</div>
		</div>

		<div class="container info">
			<div class="myBg">
				<img id="headImg" render-src="headImgUrl" class="rounded-circle"/>
				<div class="editHead" id="headBtn" ><i id="headImgBtn" class="fa fa-pencil-square fa-lg " aria-hidden="true"></i></div>
				<button  class="btn btn-outline-light ibtn " id="coverBtn">设置背景</button>
			</div>

			<form id="infoForm" method="post" >
					<input type="hidden" name="headImgUrl" render-value="headImgUrl" >
					<input type="hidden" name="coverImgUrl" render-value="coverImgUrl" >
					<input type="hidden" name="email" render-value="email" >
					 <div>
						<label>昵称</label><input type="text" name="nickName" render-value="nickName" class="form-control" >
					</div>
					<div>
						<label>性别</label><select class="form-control" render-value="gender" name="gender" >
						<option value="-1">保密</option>
						<option value="0">男</option>
						<option value="1">女</option>
					</select>
					</div>
					<div>
						<label>地区</label><input type="text" name="place" render-value="place"  class="form-control" >
					</div>
					<div>
						<label>签名</label><textarea name="sign" render-value="sign" class="form-control" rows="5" ></textarea>
					</div>
			</form>
		</div>
		
		
		
	</body>
</html>
